/**
 * 需求：添加商品，添加购物车功能
 * 1. 切片：    goods [商品切片] 、      cart [购物车切片]
 * 2. 数据：    goodsList[商拼列表]      cartList[购物车列表数据]
 * 3. reducer： addGoods 添加商品        addCart 添加购物车
 *              
 */
import {createSlice, configureStore} from '@reduxjs/toolkit'

// 创建商品切片
const goodsSlice = createSlice({
    name:'goods',
    initialState:{
        goodsList:[]
    },
    reducers:{
        addGoods(state, {payload}){
            console.log('goods payload: ', payload);
        }
    }
})

// 购物车切片
const cartSlice = createSlice({
    name:'cart',
    initialState:{
        cartList:[]
    },
    reducers:{
        addCart(state, {payload}){
            console.log('cart payload: ', payload)
        }
    }
})

// 创建数据仓库
const store = configureStore({
    reducer:{
        goods:goodsSlice.reducer,
        cart: cartSlice.reducer
    }
})
console.log(store.getState());

// 监听
store.subscribe(()=>{
    console.log(store.getState());
})

